#include "HashTable.h"


namespace Hash{
    template <class Key,class Val,class Hashfunc = DefaultHashfunc<Key>>
    class map{
        typedef pair<const Key,Val> KV_field;
        struct GetMapKey
        {
            const Key& operator ()(const KV_field& data)
            {
                return data.first;
            }
        };
    
        public:
        typedef HashTableBuket<Key,KV_field,GetMapKey,Hashfunc> MapHash;
        typedef typename MapHash::iterator iterator;
        typedef typename MapHash::const_iterator const_iterator;
        MapHash MapM_HashTable;
        pair<iterator,bool> insert(pair<Key,Val> kv)
        {
            auto tmp = MapM_HashTable.insert(kv);
            return make_pair(iterator(tmp.first.first,&MapM_HashTable,tmp.second),tmp.first.second);
        }
        iterator begin()
        {
            return MapM_HashTable.begin();
        }
        iterator end()
        {
            return MapM_HashTable.end();
        }
        const_iterator cbegin()const
        {
            return MapM_HashTable.begin();
        }
        const_iterator cend()const
        {
            return MapM_HashTable.end();
        }
        bool erase(const Key&k)
        {
            return MapM_HashTable.erase(k);
        }
        Val& operator[](const Key& k)
        {
            return (*(insert(make_pair(k,Val())).first)).second;
        }
        KV_field& find(const Key& k)
        {
            return MapM_HashTable.find(k)->n_data;
        }
    };
};